package com.zmm.member.self.util;

import com.zmm.common.base.model.ResultCode;
import com.zmm.common.constant.NumberConstant;
import com.zmm.common.exception.handle.BusinessException;
import com.zmm.common.pre.handle.Assert;
import com.zmm.member.submit.vo.OrderAddressVo;
import com.zmm.util.pattern.PatternUtil;

/**
 * @author 900045
 * @description:
 * @name CheckCustomerAddressUtils
 * @date By 2021-08-04 15:17:05
 */
public final class CheckCustomerAddressUtils {
	
	/**
	 * 校验基础的地址必填项
	 * @author: 900045
	 * @date: 2021-08-04 15:27:58
	 * @throws 
	 * @param customerAddress: 
	 * @return: void
	 **/
	public static void baseCheck(OrderAddressVo customerAddress) throws BusinessException {
		Assert.notNull(customerAddress);
		Assert.notEmpty(customerAddress.getConsigneeMobile(), "手机号码不能为空");
		Assert.notEmpty(customerAddress.getConsigneeDetail(), "详细地址不能为空");
		Assert.notEmpty(customerAddress.getConsigneeName(), "收件人不能为空");
		if(customerAddress.getConsigneeName().length() > NumberConstant.TEN) {
			throw new BusinessException(ResultCode.CONSIGNEE_LENGTH_TOO_LONG);
		}
		Assert.isPositiveInteger(customerAddress.getProvinceId(), "省不能为空");
		Assert.isPositiveInteger(customerAddress.getCityId(), "市不能为空");
		Assert.isPositiveInteger(customerAddress.getCountyId(), "区不能为空");
		if (!PatternUtil.regMobile(customerAddress.getConsigneeMobile())) {
			throw new BusinessException(ResultCode.PARAMETER_ERROR, "手机号码不正确");
		}
		if (customerAddress.getConsigneeDetail().length() > NumberConstant.ONE_HUNDRED) {
			throw new BusinessException(ResultCode.USER_ADDRESS_TOO_LONG);
		}
	}
}
